<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      @submit.native.prevent>
      <el-form-item label="字典类型" prop="dictType">
        <el-input v-model="queryParams.domain.dictType" placeholder="请输入标题名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="字典类型名称" prop="dictTypeName">
        <el-input v-model="queryParams.domain.dictTypeName" placeholder="请输入标题名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="所属模块" align="center" prop="toMoudles" />
      <el-table-column label="字典类型" align="center" prop="dictType" />
      <el-table-column label="字典名称" align="center" prop="dictTypeName" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-s-grid" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog title="添加一个字典类" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属模块" prop="toMoudles">
          <el-input v-model="form.toMoudles" placeholder="填写所属模块" />
        </el-form-item>
        <el-form-item label="字典类型" prop="dictType">
          <el-input v-model="form.dictType" placeholder="填写字典类型" />
        </el-form-item>
        <el-form-item label="字典名称" prop="dictTypeName">
          <el-input v-model="form.dictTypeName" placeholder="填写字典名称" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listData,
    addData,
    removeData
  } from "@/api/system/dictType";

  export default {
    name: "Post",
    dicts: ['sys_normal_disable'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          domain: {
            title: ""
          },
          pageNum: 1,
          pageSize: 10,
          sortName: "",
          sortOrder: ""
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          dictType: [{
            required: true,
            message: "字典类型不能为空",
            trigger: "blur"
          }],
          dictTypeName: [{
            required: true,
            message: "字典名称不能为空",
            trigger: "blur"
          }]
        },

      };
    },
    created() {
      this.getList();
    },
    methods: {
      handleDetail(row){
        this.$router.push({path:'dictValue',query:{typeId:row.typeId}});
      },
      /** 查询岗位列表 */
      getList() {
        this.loading = true;
        listData(this.queryParams).then(response => {
          this.dataList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {}
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.form = JSON.parse(JSON.stringify(row));
        this.open = true;
      },
      /** 提交按钮 */
      submitForm: function() {
        addData(this.form).then(response => {
          this.$modal.msgSuccess("添加成功");
          this.open = false;
          this.getList();
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const id = row.typeId;
        this.$confirm('是否确认删除此条数据？').then(function() {
          return removeData(id);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      // /** 导出按钮操作 */
      // handleExport() {
      //   this.download('system/post/export', {
      //     ...this.queryParams
      //   }, `post_${new Date().getTime()}.xlsx`)
      // }
    }
  };
</script>
